package leetcode_1001_1100;

public class LeeCode_1041 {
    public static void main(String[] args) {
        System.out.println(isRobotBounded("GGLLGG"));
        System.out.println(isRobotBounded("GG"));
        System.out.println(isRobotBounded("GL"));
    }
    private static boolean isRobotBounded(String instructions) {
        int dir = 1;
        int[] loc = new int[2];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < instructions.length(); j++) {
                char c = instructions.charAt(j);
                switch (c){
                    case 'G':{
                        move(loc, dir);
                        break;
                    }
                    case 'L':{
                        dir = dir == 4 ? 1 : dir + 1;
                        break;
                    }
                    case 'R':{
                        dir = dir == 1 ? 4 : dir - 1;
                        break;
                    }
                }
                if (j == instructions.length() - 1 && loc[0] == 0 && loc[1] == 0 && dir == 1){
                    return true;
                }
            }
        }
        return false;
    }
    private static void move(int[] loc, int dir){
        switch (dir){
            case 1:{
                loc[1]++;
                break;
            }
            case 2:{
                loc[0]--;
                break;
            }
            case 3:{
                loc[1]--;
                break;
            }
            case 4:{
                loc[0]++;
                break;
            }
        }
    }
}
